import axios from "axios";
//dev
let baseURL='/zhiran/admin'
export function Axios(method, url, params, data){
  const zrAxios = axios.create({
    method:method,
    baseURL:baseURL,
    data:data,
    params:params,
    headers:{
      // zrToken:store.state.zrUser.baseInfo.token
    },
    'Content-Type': 'application/json',
  })

  //拦截器
  zrAxios.interceptors.request.use(
      (config)=> {
        let nowTime = new Date().getTime();
        // if (store.state.zrUser.baseInfo.expiredTime<nowTime){
        //   store.commit('removeUserInfoFromLocalStorage')
        //   return router.push('/login')
        // }
        return config;
      },
      (error)=>{
        // Do something with request error
        return Promise.reject(error);
      }
  );


  // Add a response interceptor
  zrAxios.interceptors.response.use(
      function(response) {
        // Do something with response data
        return response;
      },
      function(error) {
        // Do something with response error
        return Promise.reject(error);
      }
  );

  return new Promise((resolve,reject)=>{
    zrAxios(url)
        .then((response)=>{
          resolve(response)
        })
        .catch((error)=>{
          reject(error)
        })
  })
}




